import request from '@/utils/request'
import { encrypt } from '@/utils/my_encrypt'

// export function login(data) {
//   // 在登录方法之前调用密码的encrypt加密算法
//   data.password = encrypt(data.password);
//   return request({
//     url: '/user/login',
//     method: 'post',
//     data
//   })
// }

export function login2(data) {
  data.password = encrypt(data.password)
  return request({
    url: '/user/login2',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  console.log("getInfo",token);
  return request({
    url: '/user/getInfo2',
    method: 'get',
    params: { token }
  })
}

export function logout(token) {
  return request({
    url: '/user/logout2',
    method: 'get',
    params: { token }
  })
}

//查询全部
export function findAll() {
  return request({
    url: '/user/find/all',
    method: 'get'
  })
}
//分页查询
export function findAll2(data) {
  return request({
    url: '/user/page',
    method: 'get',
    params:data
  })
}
//删除一个
export function deleteOne(id) {
  return request({
    url: '/user/delete',
    method: 'get',
    params:{id}
  })
}
//批量删除
export function batchdelete(ids) {
  console.log("ids="+ids);

  return request({
    url: '/user/delete/batch',
    method: 'get',
    params: {ids:ids.join(',')}
  })
}
//添加
export function addUser(data) {

  return request({
    url: '/user/add',
    method: 'post',
    data
  })
}
//修改
export function updateUser(data) {

  return request({
    url: '/user/update',
    method: 'post',
    data
  })
}
//导入
export function uploadExcel(data) {

  return request({
    url: '/user/upload/excel',
    method: 'post',
    data
  })
}

export function uploadImage(formData) {
  return request({
    url: '/user/upload',
    method: 'post',
    data: formData
  })
}

export function register(user) {
  // 需要先对密码进行加密
  user.password = encrypt(user.password);
  return request({
    url: '/user/register',
    method: 'post',
    data: user
  })
}
